﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GRWL.BZSC.UI.BaseDataSvc;
using GRWL.BZSC.UI.CustomCtrl;

namespace GRWL.BZSC.UI
{
    public partial class FindRequisitionFrm :BaseFrm
    {
        #region 自定义变量及函数
        public class SelectReq
        {
           public int ReqId{get;set;}//主表ID
           public int ReqCode { get; set; }//主表Code
           public int ReqDetailId { get; set; }//细表ID
        }
        //是否允许多选或单选
        public bool AllowMulitSelect { get; set; }
        //设定搜索条件环境
        public void SetCondition(bool MultiRec)
        {
            AllowMulitSelect = MultiRec;
        }

        public List<SelectReq> SelectReqs = new List<SelectReq>();


        private void SearchReq()
        {
            //TB_ReqDetail[] reqDetail = BaseDataProxy.Findrequs(txtCode.Text.Trim(),null,cbbStatus.Text.Trim(),dpStart.Value,dpEnd.Value,txtMaterialCode.Text.Trim(),0,txtMaterilName.Text.Trim());

            QRequisition[] requistions = BaseDataProxy.FindRequisitions(txtCode.Text.Trim(), null, cbbStatus.Text.Trim(), dpStart.Value, dpEnd.Value, txtMaterialCode.Text.Trim(), 0, txtMaterilName.Text.Trim());
            //foreach(TB_Requisition Requistion in requistions) 
            //{

            //}
        }
        #endregion

        public FindRequisitionFrm()
        {
            InitializeComponent();
            //默认允许多选
            AllowMulitSelect = true;

            this.BaseDataProxy = new BaseDataSvc.BaseDataClient();
            this.BaseDataProxy.Open();
        }

        private void FindRequisitionFrm_Load(object sender, EventArgs e)
        {
            gvRequireDetail.MultiSelect = AllowMulitSelect;
            gvRequireDetail.ReadOnly = true;
            gvRequireDetail.AutoGenerateColumns = false;

        }



        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            gvRequireDetail.Rows.Clear();
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (gvRequireDetail.SelectedRows.Count == 0)
            {
                MessageBox.Show("选择为空，请选择纪录后再确定。", "", MessageBoxButtons.OK);
                return;
            }

            foreach (DataGridViewRow rSel in gvRequireDetail.SelectedRows)
            {
                SelectReq newItem = new SelectReq();
                newItem.ReqDetailId = (int)rSel.Cells["id"].Value;
                SelectReqs.Add(newItem);
            }
            Close();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {

        }
    }
}
